package com.kantboot.system.admin.repository;

import com.kantboot.system.admin.domain.entity.SysAdminRouterPermission;
import jakarta.transaction.Transactional;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;

import java.util.List;

public interface SysAdminRouterPermissionRepository
extends JpaRepository<SysAdminRouterPermission,Long>
{

    /**
     * 根据路由获取权限编码列表
     */
    @Query("""
    SELECT rp.permissionCode
    FROM SysAdminRouterPermission AS rp
    WHERE rp.routerCode = :routerCode
    """)
    List<String> findPermissionCodeListByRouterCode(String routerCode);

    /**
     * 根据routerCode删除
     */
    @Modifying
    @Transactional
    @Query("""
    DELETE FROM SysAdminRouterPermission AS rp
    WHERE rp.routerCode = :routerCode
    """)
    void deleteByRouterCode(String routerCode);


}